<?php

// check user login
session_start();

//echo $_SESSION["user"];




class Test_doctrine_join extends CI_Controller {

	public function __construct() {
            parent::__construct(); 

	}
        
        public function index() {
            
            $variable = '12';
            
            /*
            $query = $this->doctrine->em->createQuery("select u.name from ORM\Dynasties2\Malenames u");
             $result = $query->getResult();
             print_r($result);
             
             // the above command returns: Array ( [0] => Array ( [name] => Varren ) [1] => Array ( [name] => Tyrrek ) [2] => Array ( [name] => Sarlemus ) [3] => Array ( [name] => Barrhen ) [4] => Array ( [name] => Ryzkem ) [5] => Array ( [name] => Urrim ) [6] => Array ( [name] => Nashrek ) [7] => Array ( [name] => Parnimus ) [8] => Array ( [name] => Meshka ) [9] => Array ( [name] => Johnn ) [10] => Array ( [name] => Crowen ) [11] => Array ( [name] => Demmish ) [12] => Array ( [name] => Wylum ) [13] => Array ( [name] => Heccet ) [14] => Array ( [name] => Abden ) [15] => Array ( [name] => Luccen ) [16] => Array ( [name] => Tehnik ) [17] => Array ( [name] => Gurrim ) [18] => Array ( [name] => Frederick ) [19] => Array ( [name] => Liffgem ) [20] => Array ( [name] => Wulfgang ) [21] => Array ( [name] => Bartholemew ) [22] => Array ( [name] => Hull ) [23] => Array (
            
             * 
             */
            
            //$query = $this->doctrine->em->createQuery("select u.id from ORM\Dynasties2\Characters u WHERE u.whichFamily = $variable");
		//$query = $this->doctrine->em->createQuery("select u.id from characters u WHERE u.whichFamily = $variable");


		//$query = $this -> doctrine -> em -> createQuery ("SELECT a FROM ORM\Dynasties2\Maillinks a JOIN ORM\Dynasties2\Mailmsgs b WHERE a.msgId = b.id");



		// THIS WORKS (mostly, spits out lots of weird array data
		//$query = $this -> doctrine -> em -> createQuery ("SELECT a FROM ORM\Dynasties2\Maillinks a JOIN a.mailMsg b");


		// test where  THIS WORKS
		//$query = $this -> doctrine -> em -> createQuery ("SELECT a.toUser ,b.fromUser FROM ORM\Dynasties2\Maillinks a JOIN a.mailMsg b WHERE a.toUser = '16'");
		
		$query = $this -> doctrine -> em -> createQuery ("SELECT a, b.fromUser FROM ORM\Dynasties2\Maillinks a JOIN a.mailMsg b WHERE a.toUser = '16'");


		//$query = $this -> doctrine -> em -> createQuery ("SELECT b FROM ORM\Dynasties2\Maillinks a JOIN a.mailMsg b WHERE a.toUser = '15' setHydrationMode(Doctrine::HYDRATE_OBJECT)");

		//setHydrationMode(Doctrine::HYDRATE_ARRAY);

		//$query = $this->doctrine->em->createQuery("select a from ORM\Dynasties2\Maillinks a");

            
            //$query = $this->doctrine->em->createQuery("
            //        select *
            //        from ORM\Dynasties2\Characters u
            //        WHERE u.whichFamily = $variable
            //            ");
            
             //$result = $query->getResult(Query::HYDRATE_OBJECT);
		$result = $query->getResult();
             //print_r($result);
		\Doctrine\Common\Util\Debug::dump($result);
             
             //if (empty($result)) {
             //    echo "</br>Result is empty.</br>";
             //} else {
             //    echo "</br>Result is NOT empty.</br>";
            // }

	foreach ($result as $val => $val2) {
	//print_r($val2);
	//echo $val2;



		foreach ($val2 as $col => $val3) {
			//print_r($val3);
			//echo ($val3);
			$data = $val3;
			if ($col === 'fromUser') {
			echo "</br>My data is " . $data;
			}
		}
	}
	echo "<br>-------------seperator----------------</br>";

            
            
            
        }
}